package com.wry.wallet.web;

import com.wry.wallet.entity.AccountFlow;
import com.wry.wallet.service.WalletService;
import com.wry.wallet.utils.ApiResult;
import com.wry.wallet.vo.AccountFlowVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <h1> 控制器 <h1>
 *
 * @author wry
 * @since 2023/3/31 13:20
 */
@RequestMapping("wallet")
@RestController
public class WalletController implements Serializable {

    @Resource
    private WalletService walletService;

    /**
     *
     * 查询余额
     */
    @GetMapping("balance/{accountNumber}")
    public ApiResult<BigDecimal> queryBalance(@PathVariable String accountNumber){
        return ApiResult.success(walletService.queryBalance(accountNumber));
    }

    /**
     * 方便起见，统一用GET
     *
     * 消费扣款
     */
    @GetMapping("consume/{accountNumber}/{amount}")
    public ApiResult<String> consume(@PathVariable String accountNumber,
                                     @PathVariable BigDecimal amount){
        walletService.consume(accountNumber,amount);
        return ApiResult.success("ok");
    }

    /**
     * 退款
     */
    @GetMapping("refund/{accountNumber}/{amount}")
    public ApiResult<String> refund(@PathVariable String accountNumber,
                                    @PathVariable BigDecimal amount){
        walletService.refund(accountNumber, amount);
        return ApiResult.success("ok");
    }

    /**
     * 查询账户流水
     */
    @GetMapping("flow/{accountNumber}")
    public ApiResult<List<AccountFlowVO>> flow(@PathVariable String accountNumber){
        return ApiResult.success(walletService.flow(accountNumber));
    }
}
